<?php

class Catalogue_Model_Attribute_Observer_ValueTypeUpdater extends Workset_Model_Observer_Abstract {

	protected $_data = null;

	function beforeSave(Workset_Model_Subject_Interface $object, $data = null) {

		$this->_data = null;

		if (!$object->isModified()) {
			return;
		}

		$this->_data = $object->getOldData();
	}

	function afterSave(Workset_Model_Subject_Interface $object, $data = null) {

		if (is_array($this->_data)) {

			$test = array_diff(
				array(
					$this->_data['multiple'],
					$this->_data['enum_value'],
					$this->_data['type'],
					$this->_data['mandatory'],
				),

				array(
					$object['multiple'],
					$object['enum_value'],
					$object['type'],
					$object['mandatory'],
				)
			);

			if ($test) {
				$flags = $object->getValueFlagList();
				$mask = Workset_Model_Object_Abstract::flags2Int($flags);

				$storage = $object->getStorage();
				$storage->updateValueFlags($object, $mask);
			}
		}
	}

}

?>